package zjt.IO1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

//循环读写
public class demo3 {
    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream("D:\\itcast\\文档.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            fileOutputStream = new FileOutputStream("D:\\itcastj\\aa.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //2.循环读写
            int read;
        try {
            while((read=fileInputStream.read())!=-1) {
                fileOutputStream.write(read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
